package com.lyp.activitys;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.lyp.jsonbean.CarOrdersDetailsBean;
import com.lyp.jsonbean.NoOrderBean;
import com.tjl.yangxixis.R;
import com.tjl.yangxixis.api.YangxixiApi;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class CarnoyuyueActivity extends Activity {

    private NoOrderBean.DataBean mBean;
    private List<CarOrdersDetailsBean.DataBean> mList = new ArrayList<>();

    private TextView mName, mPhone, mXing, mPingpai, mAge, mPai, mOrder, mTime;
    private ImageView mBack;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car);
        init();
    }

    private void init() {
        mBean = (NoOrderBean.DataBean) getIntent().getExtras().get("databean");
        mBack =(ImageView) findViewById(R.id.carback);
        mName = (TextView) findViewById(R.id.carname);
        mPhone = (TextView) findViewById(R.id.carphone);
        mXing = (TextView) findViewById(R.id.carxing);
        mPingpai = (TextView) findViewById(R.id.carpingpai);
        mAge = (TextView) findViewById(R.id.carage);
        mPai = (TextView) findViewById(R.id.carpai);
        mOrder = (TextView) findViewById(R.id.carorder);
        mTime = (TextView) findViewById(R.id.cartime);

        car(mBean.getO_id());

        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    //车内详情(我的任务)
    public void car(String o_id) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(YangxixiApi.APP_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        YangxixiApi api = retrofit.create(YangxixiApi.class);
        Call<CarOrdersDetailsBean> call = api.getCarOrders(o_id);
        call.enqueue(new Callback<CarOrdersDetailsBean>() {
            @Override
            public void onResponse(Call<CarOrdersDetailsBean> call, final Response<CarOrdersDetailsBean> response) {
                if (response.body().getResult() == 1) {
                    CarnoyuyueActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mList.addAll(response.body().getData());
                            mName.setText(mList.get(0).getUser_name());
                            mPhone.setText(mList.get(0).getU_phone());
                            mXing.setText(mList.get(0).getCar_type());
                            mPingpai.setText(mList.get(0).getUser_car_type());
                            mAge.setText(mList.get(0).getCar_age());
                            mPai.setText(mList.get(0).getLicense_number());
                            mOrder.setText(mList.get(0).getOrder_number());
                            mTime.setText(mList.get(0).getPay_time());
                        }
                    });
                }
            }
            @Override
            public void onFailure(Call<CarOrdersDetailsBean> call, Throwable t) {
                LogUtils.i("tag", "失败" + t.getMessage());
            }
        });
    }
}

